﻿using System;
namespace Producers.Rr.Xtee.Riik.Ee.Producer.Rr {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="RR408Request", Namespace="http://producers.rr.xtee.riik.ee/producer/rr", Target=typeof(RR408Request))]
    public class RR408RequestSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IRR408Request clazz;
        
        public RR408RequestSerializer(IRR408Request clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("PerioodiAlgus");
            if (clazz.PerioodiAlgus!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.PerioodiAlgus))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : PerioodiAlgus");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("PerioodiLopp");
            if (clazz.PerioodiLopp!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.PerioodiLopp))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : PerioodiLopp");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("ElamisKoda");
            if (clazz.ElamisKoda!=null) {
                Writer.WriteTypeAttribute("http://producers.rr.xtee.riik.ee/producer/rr", "doktyyp");
                Writer.WriteString(clazz.ElamisKoda.ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : ElamisKoda");
            }
            Writer.WriteEndElement();
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="PerioodiAlgus") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>RR408Request>PerioodiAlgus");
                }
                clazz.PerioodiAlgus = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("PerioodiAlgus")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>RR408Request>PerioodiAlgus", Reader.LocalName);
            }
            if (Reader.LocalName=="PerioodiLopp") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>RR408Request>PerioodiLopp");
                }
                clazz.PerioodiLopp = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("PerioodiLopp")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>RR408Request>PerioodiLopp", Reader.LocalName);
            }
            if (Reader.LocalName=="ElamisKoda") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>RR408Request>ElamisKoda");
                }
                clazz.ElamisKoda = new global::Producers.Rr.Xtee.Riik.Ee.Producer.Rr.Doktyyp(Reader.ReadElementString("ElamisKoda"));
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>RR408Request>ElamisKoda", Reader.LocalName);
            }
        }
    }
}
